// https://www.luogu.com.cn/problem/T160661
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int inf = 0x3f3f3f3f;
const ll infLL = 0x3f3f3f3f3f3f3f3fLL;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
#define MAX_SIZE 10
#define MAXN 100005

char row[MAXN];
int a[MAXN], n;
int f[MAXN][5], maxf[5];
/*
    1 for T end,
        f[i][1] = f[j][1] + 1
    2 for L end,
        f[i][2] = max(f[j][2], f[j][1]) + 1
    3 for T...L...T end
        f[i][3] = max(f[j][3], f[j][2]) + 1
*/

int main() {
    scanf("%d%s", &n, row + 1);
    rf(i, n) {
        if (row[i] == 'T')
            a[i] = 1;
        if (row[i] == 'L')
            a[i] = 2;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] == 0)
            rf(j, 3) f[i][j] = f[i - 1][j];

        if (a[i] == 1) {
            f[i][1] = f[i - 1][1] + 1;
            f[i][2] = f[i - 1][2];
            f[i][3] = f[i - 1][3] > 0 ? f[i - 1][3] + 1 : 0;
            if (f[i - 1][2])
                f[i][3] = max(f[i][3], f[i - 1][2] + 1);
        }
        if (a[i] == 2) {
            f[i][1] = f[i - 1][1];
            f[i][2] = f[i - 1][2] > 0 ? f[i - 1][2] + 1 : 0;
            if (f[i - 1][1])
                f[i][2] = max(f[i][2], f[i - 1][1] + 1);
            f[i][3] = f[i - 1][3];
        }

        ans = max(ans, f[i][3]);
    }

    // rf(j, 3) {
    //     rf(i, n) printf("%d", f[i][j]);
    //     puts("");
    // }
    printf("%d", ans);
}
